package net.flyinggroup.kafka.rest;

import lombok.RequiredArgsConstructor;
import net.flyinggroup.kafka.payload.Student;
import net.flyinggroup.kafka.producer.KafkaProducer;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;

@RestController
@RequestMapping("/api/v1/messages")
@RequiredArgsConstructor
public class MessageCongroller {
    private final KafkaProducer producer;

    @GetMapping("/json")
    public ResponseEntity<String> sendJsonMessage() {
        Student student = new Student();
        student.setId(Instant.now().toEpochMilli());
        producer.sendMsg(student);
        return ResponseEntity.ok("Message queued successfully as JSON");
    }
}
